//
//  AddStudentViewController.m
//  08- HomeWork
//
//  Created by dllo on 16/7/25.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "AddStudentViewController.h"

@interface AddStudentViewController () <UITextFieldDelegate>
@property (nonatomic, strong)UITextField *nameTextField;
@property (nonatomic, strong)UITextField *ageTextField;
@property (nonatomic, strong)UITextField *genderTextField;
@property (nonatomic, strong)UITextField *phoneNumberTextField;
@property (nonatomic, strong)NSDictionary *dictionary;
@end

@implementation AddStudentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"添加学员";
    // Do any additional setup after loading the view.
    _nameTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 50, self.view.frame.size.width, 80)];
    _nameTextField.placeholder = @"请输入名字";
    _nameTextField.delegate = self;
    [self.view addSubview:_nameTextField];
    
    _ageTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 140, self.view.frame.size.width, 80)];
    _ageTextField.placeholder = @"请输入年龄";
    _ageTextField.delegate = self;
    [self.view addSubview:_ageTextField];
    
    _genderTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 250, self.view.frame.size.width, 80)];
    _genderTextField.placeholder = @"请输入性别";
    _genderTextField.delegate = self;
    [self.view addSubview:_genderTextField];
    
    _phoneNumberTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 360, self.view.frame.size.width, 80)];
    _phoneNumberTextField.placeholder = @"请输入电话号码";
    _phoneNumberTextField.delegate = self;
    [self.view addSubview:_phoneNumberTextField];
    
    UIButton *button  = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(150, 400, 200, 100);
    [button setTitle:@"保存" forState:UIControlStateNormal];
    [self.view addSubview:button];
    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
}

-(void)buttonClicked:(UIButton *)button {
    NSString *name = _nameTextField.text;
    NSNumber *age = @(_ageTextField.text.integerValue) ;
    NSString *gender = _genderTextField.text;
    NSString *phoneNumber = _phoneNumberTextField.text;
    
    [_nameTextField resignFirstResponder];
    [_ageTextField resignFirstResponder];
    [_genderTextField resignFirstResponder];
    [_genderTextField resignFirstResponder];
    
    _dictionary = @{@"name":name, @"age":age, @"gender":gender, @"phoneNumber":phoneNumber};
    
    
    [self.navigationController popViewControllerAnimated:YES];
}
// 4.在一个时机让代理完成协议方法
- (void)viewWillDisappear:(BOOL)animated {
    [self.delegate AddStudentWithDetailDictionary:_dictionary];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
